package com.sh4.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sh4.dao.impl.ArticleDaoImpl;
import com.sh4.entity.Article;
import com.sh4.service.ArticleService;
import com.sh4.util.ContextHeader;

import net.sf.json.JSONObject;

@Service("articleServiceImpl")
@Transactional
public class ArticleServiceImpl implements ArticleService{
	
	@Autowired
	ArticleDaoImpl articleDaoImpl;

	@Override
	public void save(Article article) {
		
		if(article.getId() == null) {
			article.setCreateBy(ContextHeader.getUserCode());
			article.setCreateDate(new Date());
		}else {
			article.setUpdateBy(ContextHeader.getUserCode());
			article.setUpdateDate(new Date());
		}
		
		articleDaoImpl.saveOrUpdate(article);
	}

	@Override
	public List<Map<String, Object>> list(int pageSize, int pageNo, JSONObject params) {
		
		return articleDaoImpl.list(pageSize, pageNo, params);
	}

	@Override
	public void deleteArticle(Article a) {
		
		articleDaoImpl.delete(a);
		
	}

	@Override
	public Article getArticleById(String id , String type) {
		
		return articleDaoImpl.getArticleById(id,type);
	}

	@Override
	public Map<String, Object> preArticle(Date createDate , String type) {
		return articleDaoImpl.preArticle(createDate,type);
	}

	@Override
	public Map<String, Object> suffixArticle(Date createDate , String type) {
		
		return articleDaoImpl.suffixArticle(createDate,type);
	}

	@Override
	public int countAtricle(int pageSize, int pageNo, JSONObject params) {
		
		return articleDaoImpl.countArticle(params, pageSize, pageNo);
	}

	
}
